package com.ruoyi.project.sms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.sms.domain.SmsCouponUser;
import com.ruoyi.db.sms.domain.query.SmsCouponUserQueryVo;
import com.ruoyi.project.sms.service.SmsCouponUserService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 优惠券用户关联Controller
 *
 * @author yfy
 * @date 2020-04-26
 */
@Api(tags="sms管理：优惠券用户关联管理")
@RestController
@RequestMapping("/sms/coupon_user")
public class SmsCouponUserController extends BaseController
{
    @Autowired
    private SmsCouponUserService smsCouponUserService;

    @ApiOperation("查询优惠券用户关联列表")
    @PreAuthorize("@ss.hasPermi('sms:coupon_user:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsCouponUserQueryVo smsCouponUserQueryVo)
    {
        startPage();
        List<SmsCouponUser> list = smsCouponUserService.selectSmsCouponUserList(smsCouponUserQueryVo);
        return getDataTable(list);
    }

    @ApiOperation("导出优惠券用户关联列表")
    @Log(title = "优惠券用户关联", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('sms:coupon_user:export')")
    @GetMapping("/export")
    public AjaxResult export(SmsCouponUserQueryVo smsCouponUserQueryVo)
    {
        List<SmsCouponUser> list = smsCouponUserService.selectSmsCouponUserList(smsCouponUserQueryVo);
        ExcelUtil<SmsCouponUser> util = new ExcelUtil<SmsCouponUser>(SmsCouponUser.class);
        return util.exportExcel(list, "coupon_user");
    }

    @ApiOperation("获取优惠券用户关联详细信息")
    @Log(title = "优惠券用户关联", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('sms:coupon_user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smsCouponUserService.selectSmsCouponUserById(id));
    }

    @ApiOperation("新增优惠券用户关联")
    @Log(title = "优惠券用户关联", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('sms:coupon_user:add')")
    @PostMapping
    public AjaxResult add(@RequestBody SmsCouponUser smsCouponUser)
    {
        return toAjax(smsCouponUserService.insertSmsCouponUser(smsCouponUser));
    }

    @ApiOperation("修改优惠券用户关联")
    @Log(title = "优惠券用户关联", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('sms:coupon_user:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody SmsCouponUser smsCouponUser)
    {
        return toAjax(smsCouponUserService.updateSmsCouponUser(smsCouponUser));
    }

    @ApiOperation("删除优惠券用户关联")
    @Log(title = "优惠券用户关联", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('sms:coupon_user:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsCouponUserService.deleteSmsCouponUserByIds(ids));
    }
}
